package com.ccb.sc.common.util;

import com.google.common.base.Joiner;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author ken
 * @version 1.0
 * @date 2025/2/20 0:35
 */
public class IdUtil {

    public static char[] chars = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
            'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

    public static final Joiner JOIN = Joiner.on("-");

    /**
     * 获取时间戳的uuid
     * @return
     */
    public static String getTimeUUID() {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
        String timestamp = now.format(formatter);
        StringBuilder shortBuffer = new StringBuilder();
        String uuid = cn.hutool.core.util.IdUtil.fastSimpleUUID();
        for (int i = 0; i < 16; ++i){
            String str = uuid.substring(i*2, i*2 + 2);
            int x= Integer.parseInt(str,16);
            shortBuffer.append(chars[x%62]);
        }
        return JOIN.join(timestamp, shortBuffer.toString());
    }

}
